<!--用于验证提交动作时,内容的合法性-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>onsubmit事件触发</title>
    <script type="text/javascript">
        function onsubmitFun() {
            alert("静态注册表单提交 --- 发现不合法");
            return false;
        }

        window.onload = function () {
            var onsubmitObj = document.getElementById("id0001");
            onsubmitObj.onsubmit = function () {
                alert("动态注册表单提交 --- 发现不合法");
                return false;
            }
        }

    </script>
</head>
<body>

<!--静态时,在onsubmit中用JS调用函数,并将函数的返回值于以返回-->
<form action="http://localhost:8080" method="get" onsubmit="return onsubmitFun();">
    <input type="submit" value="静态注册"/>
</form>
<br/>
<!--动态时,通过标签ID获取标签,并对该标签的onsubmit方法进行重写,进而实现了onsubmit-->
<form action="http://localhost:8080" id="id0001">
    <input type="submit" value="动态注册"/>
</form>

</body>
</html>